<?php

require_once("xmlparser.php");

class XMLDistanceParser extends XMLParser {
    protected function getResult() {
        $src = htmlspecialchars($this->array["distance"]["_"]["source"]);
        $tgt = htmlspecialchars($this->array["distance"]["_"]["target"]);
        $hps = htmlspecialchars($this->array["distance"]["_"]["hops"]);
        if ($hps != "4294967295") {
            $result = "<p><strong>$src</strong> is at a distance of <strong>$hps hops</strong> to <strong>$tgt</strong>.</p>";
            $result .= "<div>";
	    
	    if ( $hps == 1 ) {
               $l = $this->array["distance"]["link"];
	       $mov = htmlspecialchars($l["_"]["movie"]);
               $src_n = htmlspecialchars($l["source"]["cdata"]);
               $src_w = htmlspecialchars($l["source"]["_"]["work"]);
               $tgt_n = htmlspecialchars($l["target"]["cdata"]);
	       $tgt_w = htmlspecialchars($l["target"]["_"]["work"]);
               $result .= "<p>$src_n (as $src_w) was in $mov with $tgt_n (as $tgt_w).</p>";
	    } else {
                foreach ($this->array["distance"]["link"] as $l ) {
		    $mov = htmlspecialchars($l["_"]["movie"]);
                    $src_n = htmlspecialchars($l["source"]["cdata"]);
		    $src_w = htmlspecialchars($l["source"]["_"]["work"]);
                    $tgt_n = htmlspecialchars($l["target"]["cdata"]);
		    $tgt_w = htmlspecialchars($l["target"]["_"]["work"]);
                    $result .= "<p>$src_n (as $src_w) was in $mov with $tgt_n (as $tgt_w).</p>";
	    	}
            }
            $result .= "</div>";
        } else {
            $result = "<p><strong>$src</strong> can not be linked to <strong>$tgt</strong> using your filters!</p>";
        }
        return $result;
    }
}
?>
